import Vue from 'vue'
import Vuex from 'vuex'
// 导入请求
import { getUser } from '../api/login.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: '',
    isLogin: false,
    genderobj: {
      0: '未知',
      1: '男',
      2: '女'
    }
  },
  mutations: {
    setUser (state, payload) {
      state.user = payload
    },
    setLogin (state, payload) {
      state.isLogin = payload
    }
  },
  actions: {
    async setUserInfo (context) {
      const res = await getUser()
      // 用context的commit 提交给mutations
      context.commit('setUser', res.data)
    }
  },
  modules: {}
})
